package com.ldxiwxr.system.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ldxiwxr.system.entity.User;
import com.ldxiwxr.system.entity.UserInfo;
import com.ldxiwxr.system.mapper.UserInfoMapper;
import com.ldxiwxr.system.service.IUserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.ldxiwxr.system.common.Constant.LOGIN_USER;

/**
 * 用户信息服务类实现类
 * @author SuBanxia
 */
@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;

    /**
     * 获取用户个人信息
     * @return UserInfo 用户信息类
     */
    @Override
    public UserInfo getUserInfo() {
        User user = (User) StpUtil.getSession().get(LOGIN_USER);
        return userInfoMapper.selectById(user.getId());
    }

    /**
     * 判断电话号码是否正确
     * @param phone 电话号码
     * @return Boolean 电话号码是否正确
     */
    @Override
    public Boolean checkPhone(String phone) {
        LambdaQueryWrapper<UserInfo> wrapper = Wrappers.<UserInfo>lambdaQuery().eq(UserInfo::getPhone, phone);
        UserInfo userInfo = userInfoMapper.selectOne(wrapper);
        return userInfo != null;
    }

}
